package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class LoanLibrary here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class LoanLibrary
{
    private ArrayList<Loan> loans;
    private static LoanLibrary Instance;
    
    private LoanLibrary()
    {
        loans = new ArrayList<Loan>();
    }
    
    public static LoanLibrary getInstance()
    {
        if(Instance == null)
        {
            Instance = new LoanLibrary();
        }
        return Instance;
    }
    
    public void addLoan(Loan _loan)
    {
        loans.add(_loan);
    }
    public void removeLoan(Loan _loan)
    {
        loans.remove(_loan);
    }
    public Loan getLoan(int _id)
    {
        boolean found = false;
        int index = 0;
        Loan retLoan = null;
        
        while(!found && index < loans.size())
        {
            Loan loan = loans.get(index);
            
            if(loan.getId() == _id)
            {
                found = true;
                retLoan = loan;
            }
            else
            {
                index++;
            }
        }
        return retLoan;
    }
}
